﻿using csharp_rentals_415.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace csharp_rentals_415.Controllers
{
    public class HomeController : Controller
    {
        private RentalService _service; // declare singleton 
        public HomeController() {
            _service = RentalService.Instance; // getting the singleton
        }


        public ActionResult Index()
        {
            // create vm
            HomeIndexVm hVm = new HomeIndexVm();
            // populate the vm with data from Singleton....
            hVm.Greeting = _service.Greeting;
            hVm.Properties = _service.Properties; // all realestate....
            //hVm.Condomieumns = ??? LINQ
            //hVm.Rentals = ??? LINQ
            //var res = _service.Properties.Where(p => p.GetType().Name == "Rentals").ToList();
            //hVm.Rentals = res

            // pass along to view
            return View(hVm);
        }
    [HttpGet]
        public ActionResult Edit(int id)
        {
            //create the vm 
            //HomeEditVm eVm = new HomeEditVm();
            //// get the correct data from the list
            //Rental tempR = _service.Rentals.FirstOrDefault(r => r.RentalId == id);
            ////populate the vm  // populate the fields
            //eVm.Address = tempR.Address;
            //eVm.Realtor = tempR.Realtor;
            //eVm.RentalId = tempR.RentalId;
            //eVm.RentAmount = tempR.RentAmount;
            //eVm.SquareFootage = tempR.SquareFootage;
            ////send vm to view // send and show to edit page
            //return View(eVm);
            return View();

        }
        [HttpPost]
    public ActionResult Edit(HomeEditVm eVm)
    {
            // save changes from vm to the list....
            // tempRental
        //Rental tR = _service.Rentals.FirstOrDefault(r => r.RentalId == eVm.RentalId);
        //tR.Address = eVm.Address;
        //tR.Realtor = eVm.Realtor;
        //tR.RentalId = eVm.RentalId;
        //tR.RentAmount = eVm.RentAmount;
        //tR.SquareFootage = eVm.SquareFootage;
        return RedirectToAction("Index");
    }




        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}